<?php
class Controller
{
	public function isLogin()
	{
		if (isset($_SESSION['user']['uname']) && isset($_SESSION['user']['passwd'])){
			$userInfo = AdminModel::get('', $_SESSION['user']['uname']);
			if ($userInfo && $userInfo['passwd']==$_SESSION['user']['passwd']){
				return true;
			}
		}
		return false;
	}
	
	public function login()
	{
		$uname = isset($_POST['uname']) && $_POST['uname'] ? trim($_POST['uname']) : Util::msgRedirect('缺少用户名');
		$passwd = isset($_POST['passwd']) && $_POST['passwd'] ? trim($_POST['passwd']) : Util::msgRedirect('缺少密码');
		$userInfo = AdminModel::get('', $uname);
		if ($userInfo && $userInfo['passwd']==md5($passwd)){
			$_SESSION['user'] = $userInfo;
			Util::msgRedirect('成功登陆', '/Admin');
		}else{
			Util::msgRedirect('帐号或密码不正确');
		}
	}
	
	public function assign($var, $val)
	{
		View::assign($var, $val);
	}
	
	public function display($tpl)
	{
		View::display("admin/$tpl.php");
	}
}
